package com.cfwx.net;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class MyServer{
	private ServerSocket ss;
	private Socket socket;
	private BufferedReader in;
	private PrintWriter out;
	public MyServer()
	{
		try
		{
			ss = new ServerSocket(9991);
			System.out.println("客户端启动成功！");
			while (true)
			{
				socket = ss.accept();
				in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
				out = new PrintWriter(socket.getOutputStream(),true);
				String line = in.readLine();
				System.out.println("client: "+line);
				out.println("you input is :" + line);
				out.flush();
				out.close();
				in.close();
				socket.close();
			}
			
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}finally{
			try {
				ss.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		
	}
	public static void main(String[] args)
	{
		new MyServer();
	}
}
